// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DisclaimerDialog.java

package com.boci.common.ui.control;

import com.boci.clientapp.main.*;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.AbstractDialog;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.logging.Logger;
import javax.swing.*;

public class DisclaimerDialog extends AbstractDialog
{

    public DisclaimerDialog(TradingClientApp owner, boolean modal, Locale pLocale)
    {
        super(owner, modal, pLocale, true);
        rootPanel = new JPanel();
        lblTitle = new JLabel();
        contentSclPane = new JScrollPane();
        taContent = new JTextArea();
        btnClose = new JButton();
        strContent_ZH_HK = null;
        strContent_ZH_CN = null;
        strContent_EN_US = null;
        msgConf = ClientAppLoader.getMessagesConfigurator();
        setSize(503, 375);
        initGUI(pLocale);
        setText(pLocale);
        hideDisclaimerPanel();
    }

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        lblTitle.setText(msgConf.getUIMessages("DISCLAIMER.HEADING", pLocale));
        if(pLocale.equals(ClientAppConst.EN_US))
        {
            if(strContent_EN_US == null)
                strContent_EN_US = retrieveContent(pLocale);
            taContent.setText(strContent_EN_US);
        } else
        if(pLocale.equals(ClientAppConst.ZH_HK))
        {
            if(strContent_ZH_HK == null)
                strContent_ZH_HK = retrieveContent(pLocale);
            taContent.setText(strContent_ZH_HK);
        } else
        if(pLocale.equals(ClientAppConst.ZH_CN))
        {
            if(strContent_ZH_CN == null)
                strContent_ZH_CN = retrieveContent(pLocale);
            taContent.setText(strContent_ZH_CN);
        }
        btnClose.setText(msgConf.getUIMessages("DISCLAIMER.CLOSE", pLocale));
        setTitle(msgConf.getUIMessages("DISCLAIMER.TITLE", pLocale));
        if(pLocale.equals(ClientAppConst.EN_US))
            taContent.setWrapStyleWord(true);
        else
            taContent.setWrapStyleWord(false);
        setTextAreaPosition();
    }

    private void setFont(Locale pLocale)
    {
        lblTitle.setFont(ClientAppLoader.getSmallBoldTextFont(pLocale));
        taContent.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        btnClose.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
    }

    public void setTextAreaPosition()
    {
        taContent.select(0, 0);
        contentSclPane.getVerticalScrollBar().setValue(0);
    }

    public void initGUI(Locale pLocale)
    {
        rootPanel.setLayout(null);
        rootPanel.setBackground(Color.WHITE);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(rootPanel, "Center");
        lblTitle.setBounds(15, 12, 300, 20);
        contentSclPane.setVerticalScrollBarPolicy(22);
        contentSclPane.setHorizontalScrollBarPolicy(31);
        contentSclPane.setBounds(15, 37, 468, 252);
        taContent.setMargin(new Insets(5, 5, 5, 7));
        taContent.setLineWrap(true);
        contentSclPane.setViewportView(taContent);
        btnClose.setBounds(200, 300, 104, 25);
        rootPanel.add(lblTitle);
        rootPanel.add(contentSclPane);
        rootPanel.add(btnClose);
        taContent.setEditable(false);
        btnClose.setActionCommand("DISCLAIM_CLOSE");
        btnClose.addActionListener(this);
        addWindowListener(new WindowAdapter() {

            public void windowOpened(WindowEvent e)
            {
                btnClose.requestFocus();
            }
        }
);
    }

    public void refresh(ResponseVO pResponseVO)
    {
        setDefFocus();
    }

    public void actionPerformed(ActionEvent e)
    {
        String strActionType = e.getActionCommand();
        ApplicationService appServ = ApplicationService.getInstance();
        if(strActionType.equals("DISCLAIM_CLOSE"))
            appServ.showDisclaimerDialog(false);
    }

    public HashMap getInputValue(String pActionType)
    {
        return null;
    }

    private String retrieveContent(Locale pLocale)
    {
        Logger logger = CMLogger.getInstance();
        String strContent = "";
        String strFileName = null;
        String newline = null;
        if(pLocale.equals(ClientAppConst.EN_US))
            strFileName = "/com/boci/common/resources/config/disclaimer_en_US.txt";
        else
        if(pLocale.equals(ClientAppConst.ZH_HK))
            strFileName = "/com/boci/common/resources/config/disclaimer_zh_HK.txt";
        else
        if(pLocale.equals(ClientAppConst.ZH_CN))
            strFileName = "/com/boci/common/resources/config/disclaimer_zh_CN.txt";
        try
        {
            newline = System.getProperty("line.separator");
        }
        catch(Exception e)
        {
            newline = "\n";
        }
        try
        {
            InputStream inReader = com.boci.clientapp.main.ClientAppLoader.class.getResourceAsStream(strFileName);
            BufferedReader br = FileUtil.getReader(inReader, "UTF-8");
            String tmpLine;
            while((tmpLine = br.readLine()) != null) 
                if(strContent.equals(""))
                    strContent = tmpLine;
                else
                    strContent = (new StringBuilder()).append(strContent).append(newline).append(tmpLine).toString();
        }
        catch(Exception sysEx)
        {
            sysEx.printStackTrace();
            logger.severe(StringUtil.formatException(sysEx));
        }
        return strContent;
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                btnClose.requestFocus();
            }
        }
);
    }

    private JPanel rootPanel;
    private JLabel lblTitle;
    private JScrollPane contentSclPane;
    private JTextArea taContent;
    private JButton btnClose;
    private MessagesConfigurator msgConf;
    private static final String ENCODE_UTF8 = "UTF-8";
    private String strContent_ZH_HK;
    private String strContent_ZH_CN;
    private String strContent_EN_US;

}
